package com.kobeliu.entity;
/**
 * 给定一个数组arr,一个值num，将小于num的值放到数组左边，等于放中间,大于num的值放到数组右边，
 */
public class Demo_9 {
    public static void main(String[] args) {

        int[] arr = {3,5,6,7,3,5,8,6,5,42,4};
        sortFunction(arr,5);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    private static void sortFunction(int[] arr, int num) {
        int left = -1;
        int right = arr.length;
        int temp = 0;
        int i = 0;

        while(i<right) {
            if(arr[i] < num){
                temp = arr[i];
                arr[i++] = arr[++left];
                arr[left] = temp;
            }else if(arr[i] > num){
                temp = arr[i];
                arr[i] = arr[--right];
                arr[right] = temp;
            }else{
                i++;
            }
        }
    }
}
